/*
 * @Author       : 魏威 <1209562577@qq.com>
 * @Date         : 2022-03-31 15:25 周4
 * @Description  :
 */

import { useEffect, useRef } from "react";

export const useDocmentTitle = (
  title: string,
  keepOnUnmount: boolean = true
) => {
  const oldTitle = useRef(document.title).current;

  useEffect(() => {
    document.title = `jira | ${title}`;
  }, [title]);

  useEffect(() => {
    return () => {
      if (!keepOnUnmount) {
        document.title = oldTitle;
      }
    };
  }, [keepOnUnmount, title]);
};
